 #include<stdio.h>
 #include<math.h>
 main()
 {
 	double a = -1,b = 1,h,temp;
 	int i,j,ch,n=500000,count1=1,count2=1,count3=1,count4=1;
	
	
	double F1(double x);
	double F2(double x);
	double F3(double x);
	double F4(double x);
	
	h = (double)1/(double)n ;
	while(1)
	{
	
	printf("\n 1. When F(x) = (2x^2 -1) .");
	printf("\n 2. When F(x) = (4x^3 - 3x) .");
	printf("\n 3. When F(x) = (8x^4 - 8x^2 + 1) .");
	printf("\n 4. When F(x) = (16x^5 - 20x^3 + 5x) .");
	printf("\n Enter your choice ( 0 to exit) :");
	scanf("%d",&ch);
	switch(ch)
	{
	case 1 :
		
		//double X1[2];
		count1=1;
		temp=0;
		for(a=-1;a < b; a=a+h)
		{
			if( F1(a)*F1(a+h) < 0)//tolerence)
			{
				temp = ((double)((2*a)+h)/(double)2) ;
				if( F1(a)*F1(temp) < 0)
				{
				 printf("\nThe %d root is --> %lf",count1, ((double)(a+temp)/(double)2));
				 count1=count1+1;
				}
				else
				{
				 printf("\nThe %d root is --> %lf",count1, ((double)(a+h+temp)/(double)2));
				 count1=count1+1;
				}
				temp=0;
			}
			
		}
		
		break;
	case 2 :
		count2=1;
		for(a=-1;a < b; a=a+h)
		{
			if( F2(a)*F2(a+h) < 0)//tolerence)
			{
				
				/*printf("\nThe %d root is --> %lf",count2, ((double)((2*a)+h)/(double)2));
				count2=count2+1;
				*/
				temp = ((double)((2*a)+h)/(double)2) ;
				if( F2(a)*F2(temp) < 0)
				{
				 printf("\nThe %d root is --> %lf",count2, ((double)(a+temp)/(double)2));
				 count2=count2+1;
				}
				else
				{
				 printf("\nThe %d root is --> %lf",count2, ((double)(a+h+temp)/(double)2));
				 count2=count2+1;
				}
				temp=0;
			}
			
		}
		
		break;
	case 3 :
		count3=1;
		for(a=-1;a < b; a=a+h)
		{
			if( F3(a)*F3(a+h) < 0)//tolerence)
			{
				
				//printf("\nThe %d root is --> %lf",count3, ((double)((2*a)+h)/(double)2));
				//count3=count3+1;
				temp = ((double)((2*a)+h)/(double)2) ;
				if( F3(a)*F3(temp) < 0)
				{
				 printf("\nThe %d root is --> %lf",count3, ((double)(a+temp)/(double)2));
				 count3=count3+1;
				}
				else
				{
				 printf("\nThe %d root is --> %lf",count3, ((double)(a+h+temp)/(double)2));
				 count3=count3+1;
				}
				temp=0;
			}
			
		}
		break;
	case 4 :
		count4=1;
		for(a=-1;a < b; a=a+h)
		{
			if( F4(a)*F4(a+h) < 0)//tolerence)
			{
				
				//printf("\nThe %d root is --> %lf",count4, ((double)((2*a)+h)/(double)2));
				//count4=count4+1;
				temp = ((double)((2*a)+h)/(double)2) ;
				if( F4(a)*F4(temp) < 0)
				{
				 printf("\nThe %d root is --> %lf",count4, ((double)(a+temp)/(double)2));
				 count4=count4+1;
				}
				else
				{
				 printf("\nThe %d root is --> %lf",count4, ((double)(a+h+temp)/(double)2));
				 count4=count4+1;
				}
				temp=0;
			}
			
		}		break;
	default : 
		printf("BYE");
		exit(0);
	}
	}
	
}
 double F1(double x)
 {
 	return (double)(2*x*x - 1);
 }
 double F2(double x)
 {
 	return (double)(4*x*x*x-3*x);
 }
 double F3(double x)
 {
 	return (double)(8*x*x*x*x-8*x*x+1);
 }
 double F4(double x)
 {
 	return (double)(16*x*x*x*x*x-20*x*x*x+5*x);
 }
